<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            background-color: black;
        }
        body {
            margin: 0px;
        }
    </style>
</head>
<body>
<canvas></canvas>   
<script>
    var canvas=document.querySelector('canvas')
    var ctx = canvas.getContext('2d')
    canvas.width=window.innerWidth;
    canvas.height=window.innerHeight;
    var arr = ['red','blue','pink','orange','yellow']
    //面向对象编程
    //构造器函数 --》生产对象
    function Demo(){
        this.x=Math.random()*window.innerWidth;
        this.y=Math.random()*window.innerHeight;
        this.r=Math.random()*15+5;
        this.color=arr[Math.floor(Math.random()*5)]
    }
    var arr1 = []
    for(var i=0;i<100;i++){
        arr1.push(new Demo())
    }
    for (var j = 0;j<arr1.length;j++){
        ctx.beginPath()
        ctx.arc(arr1[j].x,arr1[j].y,arr1[j].r,0,Math.PI*2)
        ctx.strokeStyle=arr1[j].color
        ctx.stroke()
        ctx.closePath()
    }
</script> 
</body>
</html>